﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CokoNES.Emulator.Hardware
{
    public class Cartridge
    {
        public enum Mirroring { Horizontal, Vertical, FourScreen }

        #region header

        /// <summary>
        /// The complete header
        /// </summary>
        public byte[] header = new byte[16];

        /// <summary>
        /// Size of PRG ROM in 16 KB units
        /// </summary>
        public byte PRGROM_Size;

        /// <summary>
        /// Size of CHR ROM in 8 KB units (Value 0 means the board uses CHR RAM)
        /// </summary>
        public byte CHRROM_Size;

        /// <summary>
        /// Size of PRG RAM in 8 KB units (Value 0 infers 8 KB for compatibility)
        /// </summary>
        public byte PRGRAM_Size;

        /// <summary>
        /// 76543210
        /// ||||||||
        /// ||||+||+- 0xx0: vertical arrangement/horizontal mirroring
        /// |||| ||   0xx1: horizontal arrangement/vertical mirroring
        /// |||| ||   1xxx: four-screen mirroring
        /// |||| |+-- 1: SRAM in CPU $6000-$7FFF, if present, is battery backed
        /// |||| +--- 1: 512-byte trainer at $7000-$71FF (stored before PRG data)
        /// ++++----- Lower nybble of mapper number
        /// </summary>
        public byte Flag6;

        /// <summary>
        /// 76543210
        /// ||||||||
        /// |||||||+- VS Unisystem
        /// ||||||+-- PlayChoice-10 (8KB of Hint Screen data stored after CHR data)
        /// ||||++--- If equal to 2, flags 8-15 are in NES 2.0 format
        /// ++++----- Upper nybble of mapper number
        /// </summary>
        public byte Flag7;

        /// <summary>
        /// 76543210
        /// ||||||||
        /// |||||||+- TV system (0: NTSC; 1: PAL)
        /// +++++++-- Reserved, set to zero
        /// </summary>
        public byte Flag9;

        /// <summary>
        /// 76543210
        ///   ||  ||
        ///   ||  ++- TV system (0: NTSC; 2: PAL; 1/3: dual compatible)
        ///   |+----- SRAM in CPU $6000-$7FFF is 0: present; 1: not present
        ///   +------ 0: Board has no bus conflicts; 1: Board has bus conflicts
        /// </summary>
        public byte Flag10;

        #endregion

        #region cartridge settings

        public bool trainerAvailable;
        public bool batteryAvailable;
        public byte mapper;
        public bool isVsRom;
        public bool isPlayerChoice;
        public bool isNes2Format;

        public Mirroring mirroringMod;

        #endregion

        #region data

        public byte[] Trainer_Data;
        public byte[][] PRGROM_Data;
        public byte[][] CHRROM_Data;
        public byte[] PlayChoice_Data;

        #endregion

    }
}
